﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using NewsMine.DomainObjects;

namespace NewsMine.DataManagers
{
    public class CsvReader
    {
        public List<object> GetRecords(string fileName)
        {
            var list = from line in File.ReadAllLines(fileName).Skip(1)
                       let columns = line.Split(',')
                       select new
                       {
                           Plant = columns[0],
                           Material = int.Parse(columns[1]),
                           Density = float.Parse(columns[2]),
                           StorageLocation = int.Parse(columns[3])
                       };

            return list.ToList<object>();
        }


        public List<Channel> GetChannels(string fileName)
        {
            var list = from line in File.ReadAllLines(fileName).Skip(1)
                       let columns = line.Split(',')
                       select new Channel
                       {
                           Name = columns[0],
                           DisplayName = columns[1],
                           Query= columns[2],
                           Description = columns[3],
                           Language = columns[4],
                           ParentChannelName = columns[5],
                           Rank = int.Parse( columns[6]),
                           Tags = columns[7],
                           RelatedChannels = columns[8]
                       };

            return list.ToList<Channel>();
        }


    }
}
